package me.zhengjie.sqlservice.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.RequiredArgsConstructor;
import me.zhengjie.mapper.WcsConfigurationMapper;
import me.zhengjie.pojo.entity.WcsConfiguration;
import me.zhengjie.sqlservice.WcsConfigurationService;
import me.zhengjie.state.TaskType;
import org.springframework.stereotype.Service;

@Service
@RequiredArgsConstructor
public class WcsConfigurationServiceImpl extends ServiceImpl<WcsConfigurationMapper, WcsConfiguration> implements WcsConfigurationService {
    private final WcsConfigurationMapper wcsConfigurationMapper;

    @Override
    public WcsConfiguration selectKey(String key) {
        LambdaQueryWrapper<WcsConfiguration> wcsConfigurationLambdaQueryWrapper = new LambdaQueryWrapper<>();
        wcsConfigurationLambdaQueryWrapper.eq(WcsConfiguration::getConfigKey,key);
        return wcsConfigurationMapper.selectOne(wcsConfigurationLambdaQueryWrapper);
    }

    @Override
    public boolean setValue(String configKey, int configValue) {
        LambdaUpdateWrapper<WcsConfiguration> wcsConfigurationLambdaUpdateWrapper = new LambdaUpdateWrapper<>();
        wcsConfigurationLambdaUpdateWrapper.set(WcsConfiguration::getConfigValue,configValue)
                .eq(WcsConfiguration::getConfigKey,configKey);
        return wcsConfigurationMapper.update(null, wcsConfigurationLambdaUpdateWrapper) > 0;
    }
}
